
/*!
 * \file      remote_control_app.h
 * \brief     remote_control应用头文件
 * \details
 * uart control:数据结构：校验值+总数据长度+数据长度(指令+数据)+指令+数据
 *  rx: 0x01    //同步rtc时间，每分钟同步一次
 *      0x02    //同步闹铃状态，是否闹铃
 *
     0x03    //同步时间日期到2853
 *		0x04    //power key msg
 *
 *  tx: 0x01    //同步时间日期到apt
 *      0x02    //同步闹钟时间设置到apt
 *
     0x03    //告知apt播放那一个提示音 0-单声tone,1-双声tone
 *      0x04    //更新贪睡时间
 *      0x05    //同步2853工作状态
 *
     0x06    //获取当前时间日期
 */

#ifndef _REMOTE_CONTROL_APP_H
#define _REMOTE_CONTROL_APP_H

#include <zephyr.h>
#include <misc/byteorder.h>
#include <drivers/console/uart_pipe.h>

//#define UART_DEBUG
#define MAGIC_HEAD 0xA5
#define MAGIC_END  0x5A
#define UART_MTU    40
#define UART_BUF_QUEUED 3
#define UART_DATA_VERIFY 3

#define UART_RXTX_INTERVAL		(1)


enum uart_rx_cmd {
	CMD_BT_PLAY = 0x11,
	CMD_BT_PAUSE,
	CMD_BT_VOL_ADD,
	CMD_BT_VOL_SUB,
	CMD_BT_MUSIC_PREV,
	CMD_BT_MUSIC_NEXT,
	CMD_SWITCH_APP=0x18,
	CMD_BT_DISCONNECT,
	CMD_SET_VOL,
	CMD_STATUS_QUERY,
	CMD_GET_DEVICE_NAME,
	CMD_SET_DISCOVERABLE,
	CMD_SET_CONNNECTABLE,
	CMD_CLEAR_PAIR_INFO,
	CMD_POWER_OFF=0X21,
	CMD_RESTART,
	CMD_MODIFY_BT_NAME,
	CMD_ANSWER_THE_PHONE,
	CMD_REJECT_A_CALL,
	CMD_HANGUP_CALL,
	CMD_HANGUP_THE_SECOND_CALL,
	CMD_HANGUP_CUR_ANSWER_NEXT,
	CMD_KEEP_CUR_ANSWSER_NEXT,
	CMD_SWITCH_TO_PHONE,
	CMD_DIAL_LAST_NUM,
	CMD_RECONNECT_LAST_DEVICE=0x31,				
};

struct uart_data_format {
    u8_t magic;
    u8_t data_len;
    u8_t cmd;
    union {
        //rx data struct
        u8_t param;
		u8_t bt_name[32];
    };
	u8_t check_sum;
	u8_t end;
}__packed;
struct uart_buf_info {
	u32_t _reserved;
    union{
        u8_t data[UART_MTU];//magic+len+data(cmd_type+cmd_data)
        struct uart_data_format data_info;
    };
};

extern void uart1_setting_init(void);
extern void uart1_dispatch(     u8_t *p_data);
extern void uart1_send_to_apt(     u8_t *p_data,u8_t writen_len);

#endif  // _REMOTE_CONTROL_APP_H


